Skip to content

Create ncwriter package#18

Merged
4 commits merged intomasterfrom
package_it
Oct 16, 2018
Merged

Create ncwriter package#18
4 commits merged intomasterfrom
package_it

Conversation

@mhidas
Copy link
Copy Markdown
Contributor

@mhidas mhidas commented Oct 12, 2018

WIP
Fixes #15

@mhidas
Copy link
Copy Markdown
Contributor Author

mhidas commented Oct 14, 2018

@lwgordonimos What am I missing? As far as I understand, I should be able to create a new virtualenv and then simply pip install -e ., or python setup.py test. With this setup, I can't do either. It complains about missing modules (those listed in requirements.txt). If I explicitlly install them first (pip install -r requirements.txt), then it works, but I thought pip (or setuptools) was supposted to handle that automatically when I try to do anything with the package.

Comment thread setup.py Outdated
# 'jsonschema==2.6.0',
# 'numpy>=1.13.0',
# 'netCDF4'
# ]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried specifying the required packages here, and then setting requirements.txt exactly as in aodncore, but then I couldn't run pip install -r requirements.txt

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a chicken and egg scenario... it is because it's trying to import the module in setup.py which depends on netCDF4, which hasn't been installed yet.

Importing ncwriter.version implicitly imports ncwriter, which in turn is importing from it's submodules.

Obtaining file:///home/lwgordon/git/aodn/aodn-netcdf-tools
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/lwgordon/git/aodn/aodn-netcdf-tools/setup.py", line 3, in <module>
        from ncwriter.version import __version__
      File "ncwriter/__init__.py", line 1, in <module>
        from .template import DatasetTemplate
      File "ncwriter/template.py", line 17, in <module>
        import netCDF4
    ImportError: No module named netCDF4
    
    ----------------------------------------

This works in pipeline because the top level module has an empty __init__.py, so doesn't start a chain of imports...

Interesting that most options don't advocate importing the module to source the version, which kind of makes sense to avoid this exact issue.

https://packaging.python.org/guides/single-sourcing-package-version/

Maybe we need to choose a standard mechanism for all packaging, one that doesn't import the package, and reads the file directly to avoid this popping up all the time.

I think I prefer option 3 using exec actually, because it still must be a string Python file, but doesn't involve any imports.

Also, it's good enough for the requests module, which is generally a very good place to look for "how to do things right": https://github.com/requests/requests/blob/master/setup.py#L67

Comment thread .travis.yml Outdated
- "2.7"

install:
- pip install -r requirements.txt
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exact call is implicit in Travis Python containers, so you can omit this unless it is customised somehow

@mhidas
Copy link
Copy Markdown
Contributor Author

mhidas commented Oct 15, 2018

@lwgordonimos Should be good to go now!

@ghost ghost merged commit 7863ea5 into master Oct 16, 2018
@ghost ghost deleted the package_it branch October 16, 2018 00:25
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant