diff --git a/MANIFEST.in b/MANIFEST.in index d69c943a..0377fc8d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,5 @@ +include mmgen/data/* + include README.md SIGNING_KEYS.pub LICENSE INSTALL include doc/wiki/using-mmgen/* diff --git a/mmgen/cfg.py b/mmgen/cfg.py index 1f552847..092ac6ae 100755 --- a/mmgen/cfg.py +++ b/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)] diff --git a/data_files/mmgen.cfg b/mmgen/data/mmgen.cfg similarity index 100% rename from data_files/mmgen.cfg rename to mmgen/data/mmgen.cfg diff --git a/data_files/mn_wordlist.c b/mmgen/data/mn_wordlist.c similarity index 100% rename from data_files/mn_wordlist.c rename to mmgen/data/mn_wordlist.c diff --git a/data_files/mnemonic.py b/mmgen/data/mnemonic.py similarity index 100% rename from data_files/mnemonic.py rename to mmgen/data/mnemonic.py diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index 3ef863c9..b5e943ab 100755 --- a/mmgen/globalvars.py +++ b/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 = '' diff --git a/setup.py b/setup.py index 202fd76c..a50b238f 100755 --- a/setup.py +++ b/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', diff --git a/test/test_py_d/ts_cfg.py b/test/test_py_d/ts_cfg.py index ec52be5b..fda2d4dd 100755 --- a/test/test_py_d/ts_cfg.py +++ b/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'))