2626import setuptools .command .easy_install as ei
2727from pkg_resources import Distribution as PRDistribution , normalize_path , working_set
2828from setuptools import sandbox
29+ from setuptools ._normalization import safer_name
2930from setuptools .command .easy_install import PthDistributions
3031from setuptools .dist import Distribution
3132from setuptools .sandbox import run_setup
@@ -670,11 +671,11 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg):
670671
671672 with contexts .save_pkg_resources_state ():
672673 with contexts .tempdir () as temp_dir :
673- foobar_1_archive = os .path .join (temp_dir , 'foo.bar -0.1.tar.gz' )
674+ foobar_1_archive = os .path .join (temp_dir , 'foo_bar -0.1.tar.gz' )
674675 make_nspkg_sdist (foobar_1_archive , 'foo.bar' , '0.1' )
675676 # Now actually go ahead an extract to the temp dir and add the
676677 # extracted path to sys.path so foo.bar v0.1 is importable
677- foobar_1_dir = os .path .join (temp_dir , 'foo.bar -0.1' )
678+ foobar_1_dir = os .path .join (temp_dir , 'foo_bar -0.1' )
678679 os .mkdir (foobar_1_dir )
679680 with tarfile .open (foobar_1_archive ) as tf :
680681 tf .extraction_filter = lambda member , path : member
@@ -697,7 +698,7 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg):
697698 len(foo.__path__) == 2):
698699 print('FAIL')
699700
700- if 'foo.bar -0.2' not in foo.__path__[0]:
701+ if 'foo_bar -0.2' not in foo.__path__[0]:
701702 print('FAIL')
702703 """
703704 )
@@ -718,8 +719,8 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg):
718719 # Don't even need to install the package, just
719720 # running the setup.py at all is sufficient
720721 run_setup (test_setup_py , ['--name' ])
721- except pkg_resources .VersionConflict :
722- self .fail (
722+ except pkg_resources .VersionConflict : # pragma: nocover
723+ pytest .fail (
723724 'Installing setup.py requirements caused a VersionConflict'
724725 )
725726
@@ -1120,6 +1121,8 @@ def make_nspkg_sdist(dist_path, distname, version):
11201121 package with the same name as distname. The top-level package is
11211122 designated a namespace package).
11221123 """
1124+ # Assert that the distname contains at least one period
1125+ assert '.' in distname
11231126
11241127 parts = distname .split ('.' )
11251128 nspackage = parts [0 ]
@@ -1207,10 +1210,11 @@ def create_setup_requires_package(
12071210 package itself is just 'test_pkg'.
12081211 """
12091212
1213+ normalized_distname = safer_name (distname )
12101214 test_setup_attrs = {
12111215 'name' : 'test_pkg' ,
12121216 'version' : '0.0' ,
1213- 'setup_requires' : [f'{ distname } =={ version } ' ],
1217+ 'setup_requires' : [f'{ normalized_distname } =={ version } ' ],
12141218 'dependency_links' : [os .path .abspath (path )],
12151219 }
12161220 if setup_attrs :
@@ -1259,7 +1263,7 @@ def create_setup_requires_package(
12591263 with open (os .path .join (test_pkg , 'setup.py' ), 'w' , encoding = "utf-8" ) as f :
12601264 f .write (setup_py_template % test_setup_attrs )
12611265
1262- foobar_path = os .path .join (path , f'{ distname } -{ version } .tar.gz' )
1266+ foobar_path = os .path .join (path , f'{ normalized_distname } -{ version } .tar.gz' )
12631267 make_package (foobar_path , distname , version )
12641268
12651269 return test_pkg
0 commit comments