Browse Source

move data files to package directory

- The former location of the data files, /usr/local/share/mmgen, is no longer
  used and may be safely deleted.
The MMGen Project 3 years ago
parent
commit
ea81d46
8 changed files with 20 additions and 38 deletions
  1. 2 0
      MANIFEST.in
  2. 16 4
      mmgen/cfg.py
  3. 0 0
      mmgen/data/mmgen.cfg
  4. 0 0
      mmgen/data/mn_wordlist.c
  5. 0 0
      mmgen/data/mnemonic.py
  6. 0 8
      mmgen/globalvars.py
  7. 2 15
      setup.py
  8. 0 11
      test/test_py_d/ts_cfg.py

+ 2 - 0
MANIFEST.in

@@ -1,3 +1,5 @@
+include mmgen/data/*
+
 include README.md SIGNING_KEYS.pub LICENSE INSTALL
 include doc/wiki/using-mmgen/*
 

+ 16 - 4
mmgen/cfg.py

@@ -187,12 +187,24 @@ class CfgFileSampleSys(CfgFileSample):
 	desc = 'system sample configuration file'
 	test_fn_subdir = 'usr.local.share'
 
-	@property
-	def fn_dir(self):
+	def __init__(self):
 		if os.getenv('MMGEN_TEST_SUITE_CFGTEST'):
-			return os.path.join(g.data_dir_root,self.test_fn_subdir)
+			self.fn = os.path.join(g.data_dir_root,self.test_fn_subdir,self.fn_base)
+			self.data = open(self.fn).read().splitlines()
 		else:
-			return g.shared_data_path
+			# self.fn is used for error msgs only, so file need not exist on filesystem
+			self.fn = os.path.join(os.path.dirname(__file__),'data',self.fn_base)
+			# Resource will be unpacked and then cleaned up if necessary, see:
+			#    https://docs.python.org/3/library/importlib.html:
+			#        Note: This module provides functionality similar to pkg_resources Basic
+			#        Resource Access without the performance overhead of that package.
+			#    https://importlib-resources.readthedocs.io/en/latest/migration.html
+			#    https://setuptools.readthedocs.io/en/latest/pkg_resources.html
+			try:
+				from importlib.resources import files # Python 3.9
+			except ImportError:
+				from importlib_resources import files
+			self.data = files('mmgen').joinpath('data',self.fn_base).read_text().splitlines()
 
 	def make_metadata(self):
 		return ['# Version {} {}'.format(self.cur_ver,self.computed_chksum)]

+ 0 - 0
data_files/mmgen.cfg → mmgen/data/mmgen.cfg


+ 0 - 0
data_files/mn_wordlist.c → mmgen/data/mn_wordlist.c


+ 0 - 0
data_files/mnemonic.py → mmgen/data/mnemonic.py


+ 0 - 8
mmgen/globalvars.py

@@ -145,14 +145,6 @@ class GlobalContext(Lockable):
 	else:
 		die(2,'$HOME is not set!  Unable to determine home directory')
 
-	# https://wiki.debian.org/Python:
-	#   Debian (Ubuntu) sys.prefix is '/usr' rather than '/usr/local, so add 'local'
-	# This must match the configuration in setup.py
-	shared_data_path = os.path.join(
-		sys.prefix,
-		*(['local','share'] if platform == 'linux' else ['share']),
-		proj_name.lower()
-	)
 	data_dir_root,data_dir,cfg_file = None,None,None
 	daemon_data_dir = '' # set by user
 	daemon_id = ''

+ 2 - 15
setup.py

@@ -66,12 +66,6 @@ def link_or_copy(tdir,a,b):
 	copy_owner(a,b)
 	os.chdir(cwd)
 
-class my_install(install):
-	def run(self):
-		for f in 'mmgen.cfg','mnemonic.py','mn_wordlist.c':
-			os.chmod(os.path.join('data_files',f),0o644) # required if user has non-standard umask
-		install.run(self)
-
 class my_build_py(build_py):
 	def run(self):
 		link_or_copy('test','start-coin-daemons.py','stop-coin-daemons.py')
@@ -100,19 +94,12 @@ setup(
 		platforms    = 'Linux, Debian, Ubuntu, Arch Linux, MS Windows, Raspberry Pi/Raspbian, Orange Pi/Armbian, Rock Pi/Armbian',
 		keywords     = g.keywords,
 		cmdclass     = {
-			'install': my_install,
 			'build_py': my_build_py,
 			'build_ext': my_build_ext,
 		},
 		ext_modules  = [module1],
-		# TODO:
-		# https://setuptools.readthedocs.io/en/latest/references/keywords.html:
-		#   data_files is deprecated. It does not work with wheels, so it should be avoided.
-		data_files = [('share/mmgen', [
-				'data_files/mmgen.cfg',     # source files must have 0644 mode
-				'data_files/mn_wordlist.c',
-				'data_files/mnemonic.py'
-				]),],
+		packages = ['mmgen'],
+		include_package_data = True,
 		py_modules = [
 			'mmgen.__init__',
 			'mmgen.addr',

+ 0 - 11
test/test_py_d/ts_cfg.py

@@ -24,7 +24,6 @@ class TestSuiteCfg(TestSuiteBase):
 	color = True
 
 	cmd_group = (
-		('nosysfile',          (40,'init with missing system cfg sample file', [])),
 		('sysfile',            (40,'init with system cfg sample file in place', [])),
 		('no_metadata_sample', (40,'init with unversioned cfg sample file', [])),
 		('altered_sample',     (40,'init with user-modified cfg sample file', [])),
@@ -56,16 +55,6 @@ class TestSuiteCfg(TestSuiteBase):
 			'sample':      '{}/data_dir/mmgen.cfg.sample'.format(self.tmpdir),
 		}[id_str]
 
-	def nosysfile(self):
-		t = self.spawn_test()
-		errstr = CfgFile.file_not_found_fs.format(CfgFileSampleSys.desc,self.path('shared_data')+'/mmgen.cfg')
-		t.expect(errstr)
-		for k in ('usr','sys','sample'):
-			t.expect('{} cfg file:\s+{}'.format(capfirst(k),self.path(k)),regex=True)
-			assert not os.path.exists(self.path(k)), self.path(k)
-		t.read()
-		return t
-
 	def copy_sys_sample(self):
 		os.makedirs(self.path('shared_data'),exist_ok=True)
 		shutil.copy2(self.path('ref'),self.path('sys'))